﻿using System;
using System.Collections.Generic;
using System.Web.Services;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Adex;
using Telerik.Web.UI;
using MediaMonitor.Common;
using System.Web.Security;
using System.Text;

namespace MediaMonitor.Users
{
    public partial class defaulNew : Adex.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetEmailApp();
            }
            if (Request.Cookies["User"]["Company"].ToString() == null || Request.Cookies["App"]["Email"].ToString() == null)
            {
                Response.Redirect(Utility.AppPath + "/logout.aspx");

            }


            if (Request.QueryString["Code"] != "Home")
            {
                if (!IsPostBack)
                {

                    DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                    if (dt1.Rows.Count > 0)
                    {
                        int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                        string Page = dt1.Rows[0]["Page"].ToString();
                        if (Page != "")
                        {
                            switch (Design)
                            {
                                case 1:
                                    if (Page.ToLower() != "" && Page.ToLower() != "search")
                                    {
                                        Response.Redirect("all-newsalert" + Page + ".aspx?Code=" + Page);
                                    }
                                    else if (Page.ToLower() == "search")
                                        Response.Redirect("report-newsalert-filter.aspx?Code=All");
                                    break;
                                case 2:
                                    if (Page.ToLower() != "" && Page.ToLower() != "search")
                                    {
                                        Response.Cookies["Last"]["TV"] = "TV";
                                        Response.Cookies["Last"]["Radio"] = "Radio";
                                        Response.Cookies["Last"]["Press"] = "Press";
                                        Response.Cookies["Last"]["Internet"] = "Internet";
                                        Response.Redirect("Newall-newsalert" + Page + "MultiMedia.aspx?Code=" + Page);
                                    }
                                    else if (Page.ToLower() == "search")
                                        Response.Redirect("NewAll-newsalert-Filter.aspx?Code=All");
                                    break;
                                case 3:
                                    if (Page.ToLower() != "" && Page.ToLower() != "search")
                                    {
                                        if (Page.ToLower() == "pending")
                                        {
                                            ReportFuncs rpt = new ReportFuncs();
                                            DataTable dtatle = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()));
                                            string date = dtatle.Rows[0]["LoginDate"].ToString();
                                            Response.Redirect("report-LastNewAlert.aspx?Date=" + date + "&Code=Padding");
                                        }
                                        if (Page.ToLower() == "today")
                                        {
                                            ReportFuncs rpt = new ReportFuncs();
                                            DataTable dta = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                                            string date = dta.Rows[0]["LoginDate"].ToString();
                                            Response.Redirect("report-Todaynewalert.aspx?Date=" + date);
                                        }
                                        else
                                        {
                                            Response.Redirect("report-LastNewAlert.aspx");
                                        }
                                    }
                                    else if (Page.ToLower() == "search")
                                        Response.Redirect("report-newsalert-filter2.aspx?Code=All");

                                    break;
                            }
                        }
                    }


                }
            }
            DataTable dt = SPs.NewsAlertLastCount("", "", "", "", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count >= 0)
            {
                //lnkLastAll.Text = lnkLastAll.Text + "(" + dt.Rows[0]["AllCount"].ToString() + ")";
                   


                if (dt.Rows[0]["PressCount"].ToString() == "0")
                {
                    chkLastPress.Enabled = false; lnkLastPress.Enabled = false;
                }
                if (dt.Rows[0]["RadioCount"].ToString() == "0")
                {
                    chkLastRadio.Enabled = false;
                    lnkLastRadio.Enabled = false;

                }
                if (dt.Rows[0]["InternetCount"].ToString() == "0")
                {
                    chkLastInternet.Enabled = false;
                    lnkPendingInternet.Enabled = false;
                }
                if (dt.Rows[0]["AllCount"].ToString() == "0")
                {
                    chkLastAll.Enabled = false;
                    lnkLastNewsAlert.Enabled = false;
                    lnkLastRun.Enabled = false;
                }
                if (dt.Rows[0]["TVCount"].ToString() == "0")
                {
                    chkLastTV.Enabled = false;
                    lnkLastTV.Enabled = false;
                }


                lblPressLast.Text = dt.Rows[0]["PressCount"].ToString();
                lblRadioLast.Text = dt.Rows[0]["RadioCount"].ToString();
                lblTVLast.Text = dt.Rows[0]["TVCount"].ToString();
                lblInternetLast.Text = dt.Rows[0]["InternetCount"].ToString();
                lblAllLast.Text = dt.Rows[0]["AllCount"].ToString();
            }
            DataTable dtPending = SPs.NewsAlertPendingCount(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "", "", "", "", "").GetDataSet().Tables[0];
            if (dtPending.Rows.Count >= 0)
            {
                if (dtPending.Rows[0]["PressCount"].ToString() == "0")
                {
                    chkPendingPress.Enabled = false; lnkPendingPress.Enabled = false;
                }
                if (dtPending.Rows[0]["RadioCount"].ToString() == "0")
                {
                    chkPendingRadio.Enabled = false;
                    lnkPendingRadio.Enabled = false;
                }
                if (dtPending.Rows[0]["InternetCount"].ToString() == "0")
                {
                    chkPendingInternet.Enabled = false;
                    lnkPendingInternet.Enabled = false;
                }
                if (dtPending.Rows[0]["AllCount"].ToString() == "0")
                {
                    chkPendingAll.Enabled = false;
                    lnkPendingAll.Enabled = false;
                    lnkPendingRun.Enabled = false;
                }
                if (dtPending.Rows[0]["TVCount"].ToString() == "0")
                {
                    chkPendingTV.Enabled = false;
                    lnkPendingTV.Enabled = false;
                }
                lblAllPending.Text = dtPending.Rows[0]["AllCount"].ToString();
                lblPressPending.Text = dtPending.Rows[0]["PressCount"].ToString();
                lblRadioPending.Text = dtPending.Rows[0]["RadioCount"].ToString();
                lblTVPending.Text = dtPending.Rows[0]["TVCount"].ToString();
                lblInternetPending.Text = dtPending.Rows[0]["InternetCount"].ToString();
            }
            DataTable dtToday = SPs.NewsAlertTodayCount(DateTime.Now.ToShortDateString() + " 00:00:00.000", Request.Cookies["User"]["Company"].ToString(), "", "", "", "", "", "").GetDataSet().Tables[0];
            if (dtToday.Rows.Count >= 0)
            {
                if (dtToday.Rows[0]["PressCount"].ToString() == "0")
                {
                    chkTodayPress.Enabled = false;
                    lnkTodayPress.Enabled = false;
                    
                }
                if (dtToday.Rows[0]["RadioCount"].ToString() == "0")
                {
                    chkTodayRadio.Enabled = false;
                    lnkTodayRadio.Enabled = false;
                }
                if (dtToday.Rows[0]["InternetCount"].ToString() == "0")
                {
                    chkTodayInternet.Enabled = false;
                    lnkTodayInternet.Enabled = false;
                }
                if (dtToday.Rows[0]["AllCount"].ToString() == "0")
                {
                    chkTodayAll.Enabled = false;
                    lnkTodayAll.Enabled = false;
                   
                }
                if (dtToday.Rows[0]["TVCount"].ToString() == "0")
                {
                    chkTodayTV.Enabled = false;
                    lnkTodayTV.Enabled = false;
                
                }
                        
                        
                lblAllToday.Text = dtToday.Rows[0]["AllCount"].ToString();
                lblPressToday.Text = dtToday.Rows[0]["PressCount"].ToString();
                lblRadioToday.Text = dtToday.Rows[0]["RadioCount"].ToString();
                lblTVToday.Text = dtToday.Rows[0]["TVCount"].ToString();
                lblInternetToday.Text = dtToday.Rows[0]["InternetCount"].ToString();
            }

            Response.Cookies["Last"]["TV"] = null;
            Response.Cookies["Last"]["Radio"] = null;
            Response.Cookies["Last"]["Press"] = null;
            Response.Cookies["Last"]["Internet"] = null;
            Response.Cookies["Last"].Expires = DateTime.Now.AddDays(1);

        }
        private void GetEmailApp()
        {
            DataTable dt = SPs.GetAllEmailPassword("", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                string code = dt.Rows[0]["Password"].ToString();
                Response.Cookies["App"]["Email"] = dt.Rows[0]["Email"].ToString();
                string strmsg = string.Empty;
                byte[] encode = new byte[code.Length];
                encode = Encoding.UTF8.GetBytes(code);
                strmsg = Convert.ToBase64String(encode);
                Response.Cookies["App"]["Password"] = strmsg;
                Response.Cookies["App"].Expires = DateTime.Now.AddYears(1);
            }
        }
        protected void lnkLastTV_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), "TV", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("all-newsalertLast.aspx?Code=tv");
                            break;
                        case 2:
                            Response.Redirect("Newall-newsalertLast.aspx?Code=tv");
                            break;
                        case 3:
                            Response.Redirect("Report-LastNewAlert.aspx");
                            break;
                    }
                }
                else
                    Response.Redirect("Newall-newsalertLast.aspx?Code=tv");
            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkLastRadio_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), "Radio", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("all-newsalertLast.aspx?Code=Radio");
                            break;
                        case 2:
                            Response.Redirect("Newall-newsalertLast.aspx?Code=Radio");
                            break;
                        case 3:
                            Response.Redirect("Report-LastNewAlert.aspx");
                            break;
                    }
                }
                else
                    Response.Redirect("Newall-newsalertLast.aspx?Code=Radio");
            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkLastInternet_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), "Internet", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("all-newsalertLast.aspx?Code=Internet");
                            break;
                        case 2:
                            Response.Redirect("Newall-newsalertLast.aspx?Code=Internet");
                            break;
                        case 3:
                            Response.Redirect("Report-LastNewAlert.aspx");
                            break;
                    }
                }
                else
                    Response.Redirect("Newall-newsalertLast.aspx?Code=Internet");

            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkLastNewsAlert_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), "last", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("all-newsalertLast.aspx?Code=last");
                            break;
                        case 2:
                            Response.Cookies["Last"]["TV"] = "TV";
                            Response.Cookies["Last"]["Radio"] = "Radio";
                            Response.Cookies["Last"]["Press"] = "Press";
                            Response.Cookies["Last"]["Internet"] = "Internet";
                            Response.Redirect("NewAll-newsalertLastMultiMedia.aspx?Code=last");
                            break;
                        case 3:
                            Response.Redirect("Report-LastNewAlert.aspx");
                            break;
                    }
                }
                else
                {
                    Response.Cookies["Last"]["TV"] = "TV";
                    Response.Cookies["Last"]["Radio"] = "Radio";
                    Response.Cookies["Last"]["Press"] = "Press";
                    Response.Cookies["Last"]["Internet"] = "Internet";
                    Response.Redirect("NewAll-newsalertLastMultiMedia.aspx?Code=last");
                }

            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkLastPress_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), "Press", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("all-newsalertLast.aspx?Code=Press");
                            break;
                        case 2:
                            Response.Redirect("Newall-newsalertLast.aspx?Code=Press");
                            break;
                        case 3:
                            Response.Redirect("Report-LastNewAlert.aspx");
                            break;
                    }
                }
                else
                    Response.Redirect("Newall-newsalertLast.aspx?Code=Press");
            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }

        protected void lnkPendingTV_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "TV", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertPending.aspx?Code=TV");
                            break;
                        case 2:
                            Response.Redirect("Newall-NewsAlertPending.aspx?Code=TV");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtPending = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtPending.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-LastNewAlert.aspx?Date=" + date + "&Code=Padding");
                            break;
                    }
                }

                else
                {
                    Response.Redirect("Newall-NewsAlertPending.aspx?Code=TV");
                }

            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkPendingRadio_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "Radio", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertPending.aspx?Code=Radio");
                            break;
                        case 2:
                            Response.Redirect("Newall-NewsAlertPending.aspx?Code=Radio");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtPending = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtPending.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-LastNewAlert.aspx?Date=" + date + "&Code=Padding");
                            break;
                    }
                }

                else
                {
                    Response.Redirect("Newall-NewsAlertPending.aspx?Code=Radio");
                }

            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }

        }
        protected void lnkPendingPress_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "Press", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertPending.aspx?Code=Press");
                            break;
                        case 2:
                            Response.Redirect("Newall-NewsAlertPending.aspx?Code=Press");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtPending = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtPending.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-LastNewAlert.aspx?Date=" + date + "&Code=Padding");
                            break;
                    }
                }

                else
                {
                    Response.Redirect("Newall-NewsAlertPending.aspx?Code=Press");
                }


            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkPendingInternet_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "Internet", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertPending.aspx?Code=Internet");
                            break;
                        case 2:
                            Response.Redirect("Newall-NewsAlertPending.aspx?Code=Internet");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtPending = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtPending.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-LastNewAlert.aspx?Date=" + date + "&Code=Padding");
                            break;
                    }
                }

                else
                {
                    Response.Redirect("Newall-NewsAlertPending.aspx?Code=Internet");
                }


            }

            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkPendingAll_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "pending", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertPending.aspx?Code=pending");
                            break;
                        case 2:
                            Response.Redirect("Newall-NewsAlertPending.aspx?Code=pending");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtPending = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtPending.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-LastNewAlert.aspx?Date=" + date + "&Code=Padding");
                            break;
                    }
                }

                else
                {
                    Response.Redirect("Newall-NewsAlertPending.aspx?Code=pending");
                }


            }


            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }

        protected void lnkTodayTV_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", "TV", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertToday.aspx?Code=TV");
                            break;
                        case 2:
                            Response.Redirect("Newall-NewsAlertToday.aspx?Code=TV");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtToday = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtToday.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-Todaynewalert.aspx?Date=" + date);
                            break;
                    }
                }

                else
                {
                    Response.Redirect("Newall-NewsAlertToday.aspx?Code=TV");
                }


            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkTodayRadio_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", "Radio", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertToday.aspx?Code=Radio");
                            break;
                        case 2:
                            Response.Redirect("Newall-NewsAlertToday.aspx?Code=Radio");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtToday = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtToday.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-Todaynewalert.aspx?Date=" + date);
                            break;
                    }
                }

                else
                {
                    Response.Redirect("Newall-NewsAlertToday.aspx?Code=Radio");
                }


            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkTodayPress_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", "Press", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertToday.aspx?Code=Press");
                            break;
                        case 2:
                            Response.Redirect("Newall-NewsAlertToday.aspx?Code=Press");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtToday = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtToday.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-Todaynewalert.aspx?Date=" + date);
                            break;
                    }
                }

                else
                {
                    Response.Redirect("Newall-NewsAlertToday.aspx?Code=Press");
                }


            }

            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkTodayInternet_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", "Internet", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertToday.aspx?Code=Internet");
                            break;
                        case 2:
                            Response.Redirect("Newall-NewsAlertToday.aspx?Code=Internet");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtToday = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtToday.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-Todaynewalert.aspx?Date=" + date);
                            break;
                    }
                }

                else
                {
                    Response.Redirect("Newall-NewsAlertToday.aspx?Code=Internet");
                }


            }
            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkTodayAll_Click1(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", "Today", "", "").GetDataSet().Tables[0];
            if (dt.Rows.Count > 0)
            {
                DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
                if (dt1.Rows.Count > 0)
                {
                    int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                    switch (Design)
                    {
                        case 1:
                            Response.Redirect("All-NewsAlertToday.aspx?Code=Today");
                            break;
                        case 2:
                            Response.Cookies["Last"]["TV"] = "TV";
                            Response.Cookies["Last"]["Radio"] = "Radio";
                            Response.Cookies["Last"]["Press"] = "Press";
                            Response.Cookies["Last"]["Internet"] = "Internet";
                            Response.Redirect("NewAll-newsalertTodayMultiMedia.aspx?Code=Today");
                            break;
                        case 3:
                            ReportFuncs rpt = new ReportFuncs();
                            DataTable dtToday = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                            string date = dtToday.Rows[0]["LoginDate"].ToString();
                            Response.Redirect("report-Todaynewalert.aspx?Date=" + date);
                            break;
                    }
                }

                else
                {
                    Response.Cookies["Last"]["TV"] = "TV";
                    Response.Cookies["Last"]["Radio"] = "Radio";
                    Response.Cookies["Last"]["Press"] = "Press";
                    Response.Cookies["Last"]["Internet"] = "Internet";
                    Response.Redirect("NewAll-newsalertTodayMultiMedia.aspx?Code=Today");
                }


            }

            else
            {
                string script = "alert(\"No Record Found For Your Search!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
            }
        }
        protected void lnkSearchforNewsAlertTV_Click1(object sender, EventArgs e)
        {
            DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
            if (dt1.Rows.Count > 0)
            {
                int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                switch (Design)
                {
                    case 1:
                        Response.Redirect("report-newsalert-filter.aspx?Code=All");
                        break;
                    case 2:
                        Response.Redirect("NewAll-newsalert-Filter.aspx?Code=All");
                        break;
                    case 3:
                        Response.Redirect("report-newsalert-filter2.aspx?Code=");
                        break;
                }
            }

            else
            {
                Response.Redirect("NewAll-newsalert-Filter.aspx?Code=All");
            }

        }

        protected void lnkSearchforNewsAlertChart_Click1(object sender, EventArgs e)
        {
            DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
            if (dt1.Rows.Count > 0)
            {
                int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                switch (Design)
                {
                    case 1:
                        Response.Redirect("SearchVideo.aspx");
                        break;
                    case 2:
                        Response.Redirect("NewAll-newsalertVideo-Filter.aspx");
                        break;
                    case 3:
                        Response.Redirect("NewAll-newsalertVideo-Filter.aspx");
                        break;
                }
            }

            else
            {
                Response.Redirect("NewAll-newsalertVideo-Filter.aspx");
            }

        }

        protected void lnkLastRun_Click1(object sender, EventArgs e)
        {
            string code = "";
            if (chkLastTV.Checked)
            {
                Response.Cookies["Last"]["TV"] = "TV";
                code += "TV,";
            }
            else
                Response.Cookies["Last"]["TV"] = null;
            if (chkLastRadio.Checked)
            {
                Response.Cookies["Last"]["Radio"] = "Radio";
                code += "Radio,";
            }
            else
                Response.Cookies["Last"]["Radio"] = null;
            if (chkLastPress.Checked)
            {
                Response.Cookies["Last"]["Press"] = "Press";
                code += "Press,";
            }
            else
                Response.Cookies["Last"]["Press"] = null;

            if (chkLastInternet.Checked)
            {
                Response.Cookies["Last"]["Internet"] = "Internet";
                code += "Internet,";
            }
            else
                Response.Cookies["Last"]["Internet"] = null;

            Response.Cookies["Last"].Expires = DateTime.Now.AddDays(1);



            if (!chkLastTV.Checked && !chkLastRadio.Checked && !chkLastPress.Checked && !chkLastInternet.Checked && !chkLastAll.Checked)
            {
                string script = "alert(\"Please select atleast one Media!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                return;
            }
            DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
            if (dt1.Rows.Count > 0)
            {
                int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                switch (Design)
                {
                    case 1:
                        if (chkLastAll.Checked)
                            Response.Redirect("all-newsalertLast.aspx?Code=last");
                        Response.Cookies["Last"].Expires = DateTime.Now.AddDays(1);
                        if (!chkLastTV.Checked && !chkLastRadio.Checked && !chkLastPress.Checked && !chkLastInternet.Checked && !chkLastAll.Checked)
                        {
                            string script = "alert(\"Please select atleast one Media!\");";
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                        }
                        else
                            Response.Redirect("all-newsalertLast.aspx?Code=");
                        break;
                    case 2:
                        if (code.TrimEnd(',') != "")
                        {

                            DataTable dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), code, "", "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                            {
                                if (code.Contains(","))
                                {
                                    Response.Redirect("NewAll-newsalertLastMultiMedia.aspx?Code=last");
                                }
                                else
                                    Response.Redirect("Newall-newsalertLast.aspx?Code=");
                            }
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }
                        }
                        else
                        {
                            DataTable dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), "last", "", "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                            {
                                Response.Cookies["Last"]["TV"] = "TV";
                                Response.Cookies["Last"]["Radio"] = "Radio";
                                Response.Cookies["Last"]["Press"] = "Press";
                                Response.Cookies["Last"]["Internet"] = "Internet";
                                Response.Redirect("NewAll-newsalertLastMultiMedia.aspx?Code=last");
                            }
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }
                        }
                        break;
                    case 3:
                        Response.Redirect("Report-LastNewAlert.aspx");
                        break;
                }
            }
            else
            {
                Response.Cookies["Last"]["TV"] = "TV";
                Response.Cookies["Last"]["Radio"] = "Radio";
                Response.Cookies["Last"]["Press"] = "Press";
                Response.Cookies["Last"]["Internet"] = "Internet";
                Response.Redirect("NewAll-newsalertLastMultiMedia.aspx?Code=last");
            }

        }
        protected void lnkPendingRun_Click1(object sender, EventArgs e)
        {
            string code = "";
            if (chkPendingTV.Checked)
            {

                Response.Cookies["Last"]["TV"] = "TV";
                code += "TV,";
            }
            else
                Response.Cookies["Last"]["TV"] = "";
            if (chkPendingRadio.Checked)
            {
                Response.Cookies["Last"]["Radio"] = "Radio";
                code += "Radio,";
            }
            else
                Response.Cookies["Last"]["Radio"] = "";
            if (chkPendingPress.Checked)
            {
                Response.Cookies["Last"]["Press"] = "Press";
                code += "Press,";
            }
            else
                Response.Cookies["Last"]["Press"] = "";
            if (chkPendingInternet.Checked)
            {
                Response.Cookies["Last"]["Internet"] = "Internet";
                code += "Internet,";
            }
            else
                Response.Cookies["Last"]["Internet"] = "";
            Response.Cookies["Last"].Expires = DateTime.Now.AddDays(1);
            if (!chkPendingTV.Checked && !chkPendingRadio.Checked && !chkPendingPress.Checked && !chkPendingInternet.Checked && !chkPendingAll.Checked)
            {
                string script = "alert(\"Please select atleast one Media!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                return;
            }
            DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
            if (dt1.Rows.Count > 0)
            {
                int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                switch (Design)
                {
                    case 1:
                        if (code != "")
                        {
                            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", code, "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                                Response.Redirect("All-NewsAlertPending.aspx?Code=");
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }
                        }
                        else
                        {
                            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "pending", "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                                Response.Redirect("All-NewsAlertPending.aspx?Code=pending");
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }
                        }
                        break;
                    case 2:
                        if (code.TrimEnd(',') != "")
                        {
                            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", code, "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                                if (code.Contains(","))
                                {
                                    Response.Redirect("NewAll-newsalertPendingMultiMedia.aspx?Code=pending");
                                }
                                else
                                    Response.Redirect("Newall-NewsAlertPending.aspx?Code=");
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }
                        }
                        else
                        {
                            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "pending", "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                            {
                                Response.Cookies["Last"]["TV"] = "TV";
                                Response.Cookies["Last"]["Radio"] = "Radio";
                                Response.Cookies["Last"]["Press"] = "Press";
                                Response.Cookies["Last"]["Internet"] = "Internet";
                                Response.Redirect("NewAll-newsalertPendingMultiMedia.aspx?Code=pending");
                            }
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }
                        }
                        break;
                    case 3:
                        ReportFuncs rpt = new ReportFuncs();
                        DataTable dtPending = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                        string date = dtPending.Rows[0]["LoginDate"].ToString();
                        Response.Redirect("report-LastNewAlert.aspx?Date=" + date + "&Code=Padding");
                        break;
                }
            }
            else
            {
                Response.Cookies["Last"]["TV"] = "TV";
                Response.Cookies["Last"]["Radio"] = "Radio";
                Response.Cookies["Last"]["Press"] = "Press";
                Response.Cookies["Last"]["Internet"] = "Internet";
                Response.Redirect("NewAll-newsalertLastMultiMedia.aspx?Code=last");
            }



        }
        protected void lnkTodayRun_Click1(object sender, EventArgs e)
        {
            string code = "";
            if (chkTodayTV.Checked)
            {
                Response.Cookies["Last"]["TV"] = "TV";
                code += "TV,";
            }
            else
                Response.Cookies["Last"]["TV"] = "";
            if (chkTodayRadio.Checked)
            {
                Response.Cookies["Last"]["Radio"] = "Radio";
                code += "Radio,";
            }
            else
                Response.Cookies["Last"]["Radio"] = "";

            if (chkTodayPress.Checked)
            {
                Response.Cookies["Last"]["Press"] = "Press";
                code += "Press,";
            }
            else
                Response.Cookies["Last"]["Press"] = "";
            if (chkTodayInternet.Checked)
            {
                Response.Cookies["Last"]["Internet"] = "Internet";
                code += "Internet,";
            }
            else
                Response.Cookies["Last"]["Internet"] = "";

            Response.Cookies["Last"].Expires = DateTime.Now.AddDays(1);
            if (!chkTodayTV.Checked && !chkTodayRadio.Checked && !chkTodayPress.Checked && !chkTodayInternet.Checked && !chkTodayAll.Checked)
            {
                string script = "alert(\"Please select atleast one Media!\");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                return;
            }


            DataTable dt1 = SPs.Configuración(Convert.ToInt32(Request.Cookies["User"]["UserID"])).GetDataSet().Tables[0];
            if (dt1.Rows.Count > 0)
            {
                int Design = Convert.ToInt32(dt1.Rows[0]["Design"]);
                switch (Design)
                {
                    case 1:
                        if (code != "")
                        {
                            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", code, "", "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                            {
                                Response.Redirect("All-NewsAlertToday.aspx?Code=");
                            }
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }
                        }
                        else
                        {
                            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", "Today", "", "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                                Response.Redirect("All-NewsAlertToday.aspx?Code=Today");
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }

                        }
                        break;
                    case 2:
                        if (code.TrimEnd(',') != "")
                        {
                            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", code, "", "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                            {
                                if (code.Contains(","))
                                {
                                    Response.Redirect("NewAll-newsalertTodayMultiMedia.aspx?Code=");
                                }
                                else
                                    Response.Redirect("Newall-NewsAlertToday.aspx?Code=");
                            }
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }
                        }
                        else
                        {
                            DataTable dt = SPs.NewaAlertToday(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", "Today", "", "").GetDataSet().Tables[0];
                            if (dt.Rows.Count > 0)
                            {
                                Response.Cookies["Last"]["TV"] = "TV";
                                Response.Cookies["Last"]["Radio"] = "Radio";
                                Response.Cookies["Last"]["Press"] = "Press";
                                Response.Cookies["Last"]["Internet"] = "Internet";
                                Response.Redirect("NewAll-newsalertTodayMultiMedia.aspx?Code=Today");
                            }
                            else
                            {
                                string script = "alert(\"No Record Found For Your Search!\");";
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
                            }

                        }
                        break;
                    case 3:
                        ReportFuncs rpt = new ReportFuncs();
                        DataTable dtToday = rpt.GetReport_NewsAlertOnDate(Convert.ToInt32(Request.Cookies["User"]["UserID"]));
                        string date = dtToday.Rows[0]["LoginDate"].ToString();
                        Response.Redirect("report-Todaynewalert.aspx?Date=" + date);
                        break;
                }
            }

            else
            {
                Response.Cookies["Last"]["TV"] = "TV";
                Response.Cookies["Last"]["Radio"] = "Radio";
                Response.Cookies["Last"]["Press"] = "Press";
                Response.Cookies["Last"]["Internet"] = "Internet";
                Response.Redirect("NewAll-newsalertTodayMultiMedia.aspx?Code=Today");
            }





        }
    }
}